<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>后台模板SpringbootDemo版本</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <link rel="stylesheet" href="/static/ztree/css/metroStyle/metroStyle.css">
        <script src="/static/js/jquery.min.js" charset="utf-8"></script>
        <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script src="/static/js/ztree.js" charset="utf-8"></script>
        <script src="/static/js/excheck.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>
    <body>


        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="rPassword" class="layui-form-label">
                            <span class="x-red">*</span> 旧密码
                        </label>
                        <div class="layui-input-inline" >
                          <input type="password" id="rPassword" name="rPassword" required="" lay-verify="required"
                                   autocomplete="off" class="layui-input">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label for="newPassword" class="layui-form-label">
                            <span class="x-red">*</span>新密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="password" id="newPassword" name="newPassword" required="" lay-verify="required"
                                   autocomplete="off" class="layui-input">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label for="surePassword" class="layui-form-label">
                            <span class="x-red">*</span>重复密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="password" id="surePassword" name="surePassword" required="" lay-verify="required|confirmPass"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button  class="layui-btn" lay-filter="add" lay-submit="" style="margin-left: 111px;">
                            确定
                        </button>
                    </div>
                </form>
            </div>
        </div>
        <script>
            layui.use(['form', 'layer'],
               function() {
                    $ = layui.jquery;
                    var form = layui.form,
                    layer = layui.layer;
                   //自定义验证规则
                   form.verify({
                       confirmPass: function (value) {
                           if ($('input[name=newPassword]').val() != value)
                               return '两次密码输入不一致！';
                       }
                   });




                       //监听提交
                    form.on('submit(add)',function(data){
                        //校验旧密码

                        $.ajax({
                            url:"/system/user/password",
                            type:"put",
                            dateType:'json',
                            data:{
                                "oldPassword" : data.field.rPassword,
                                "newPassword" : data.field.newPassword

                            },
                            success:function(result){
                                if(result.code == 0){
                                    layer.alert("修改密码成功",{icon:6},function(){
                                        //关闭当前frame
                                        xadmin.close();
                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });

                                }else if(result.code == 1){
                                    layer.alert(result.message,{icon:6});
                                }

                            }
                        });






                        return false;
                    });




            }




            );
        </script>

    </body>

</html>
